$(document).ready(function(){

	
	$("#deskCode").change(function(){
		var deskCode = $(this).find("option:selected").val();
		//alert(deskCode);
		location.href = '/seminar/seminarList.desk?deskCode='+deskCode;
	});
	
	$("#deleteSeminar").click(function(){
		var seminarSeq = $("#seminarSeq").val();
		var pageNumber = $("#pageNumber").val();
		var deskCode = $("#deskCode").val();
		var fileName = $("#fileName").val();
		var picName = $("#picName").val();
		var fileSeq = $("#fileSeq").val();
		var pathName = $("#pathName").val();
		
		if(confirm("해당글을 정말로 삭제하시겠습니까?")){
			location.href = '/seminar/seminarDelete.desk?deskCode='+deskCode+'&seminarSeq='+seminarSeq+'&pageNumber='+pageNumber+'&fileName='+fileName+'&fileSeq='+fileSeq+'&picName='+picName+'&pathName='+pathName;
		}else{
			return;
		}
	});
	
	$("#seminarFileDel").click(function(){
		if(confirm("해당파일을 삭제하시겠습니까?")){
			$("#deleteForm1").submit();
		}
	});
	
	$("#seminarPicDel").click(function(){
		if(confirm("해당파일을 삭제하시겠습니까?")){
			$("#deleteForm2").submit();
		}
	});
	
	$("#btn_seminar_edit").click(function(){
		var startDate = $("input[name='startDate']");
		var place = $("input[name='place']");
		var seminarTitle = $("input[name='seminarTitle']");
		var attendCount = $("input[name='attendCount']");
		var discussIssue = $("textarea[name='discussIssue']");
		
		
		if(!input_nullCheck(startDate, "개최일자"))
		{
			return;
		}
		
		if(!input_nullCheck(place, "장소"))
		{
			return;
		}
		
		if(!input_nullCheck(seminarTitle, "설명회 주제"))
		{
			return;
		}
		
		if(attendCount.val())
		{
			if(!check_numeric(attendCount, "참석자"))
			{
				return;
			}
		}
		
		if(!input_nullCheck(discussIssue, "주요내용"))
		{
			return;
		}
		
		
		$("form[name='seminar_mod_form']").submit();
	});
	
	$("#selectedYear").change(function(){
		var selectedYear = $(this).find("option:selected").val();
		var where = $("#where").val();
		//alert("11");
		if(where == 'seminar'){
			location.href = '/analysis/analysisSeminarList.desk?selectedYear='+selectedYear;
		}else if(where == 'channel'){
			location.href = '/analysis/analysisChannelList.desk?selectedYear='+selectedYear;
		}else if(where == 'promote'){
			location.href = '/analysis/analysisPromoteList.desk?selectedYear='+selectedYear;
		}else{}
	});
	
	$("#deleteInvade").click(function(){
		var invadeSeq = $("#invadeSeq").val();
		var pageNumber = $("#pageNumber").val();
		var deskCode = $("#deskCode").val();
		var fileName = $("#fileName").val();
		var fileSeq = $("#fileSeq").val();
		
		if(confirm("해당글을 정말로 삭제하시겠습니까?")){
			location.href = '/invade/invadeDelete.desk?deskCode='+deskCode+'&invadeSeq='+invadeSeq+'&pageNumber='+pageNumber+'&fileName='+fileName+'&fileSeq='+fileSeq;
		}else{
			return;
		}
	});
	
	$("#invadeFileDel").click(function(){
		var invadeSeq = $("#invadeSeq").val();
		var pageNumber = $("#pageNumber").val();
		var deskCode = $("#deskCode").val();
		var fileName = $("#fileName").val();
		var fileSeq = $("#fileSeq").val();
		//alert(fileSeq);
		if(confirm("해당 파일을 정말로 삭제하시겠습니까?")){
			location.href = '/invade/invadeDeleteFile.desk?deskCode='+deskCode+'&invadeSeq='+invadeSeq+'&pageNumber='+pageNumber+'&fileName='+fileName+'&fileSeq='+fileSeq;
		}else{
			return;
		}
	});
	
	$("#btn_invade_edit").click(function(){
		var companySeq = $("input[name='companySeq']");
		var customerSeq = $("input[name='customerSeq']");
		
		var consultingDate = $("input[name='consultingDate']");
		
		
		if(!input_nullCheck(companySeq, "회사 및 담당자명"))
		{
			return;
		}
		
		if(!input_nullCheck(customerSeq, "회사및 담당자명"))
		{
			return;
		}
		
		if(!input_nullCheck(consultingDate, "상담일자"))
		{
			return;
		}
				
		$("form[name='invade_mod_form']").submit();
	});
	
	
	$("#complete_invade_edit").click(function(){
		var agentCompanySeq = $("input[name='agentCompanySeq']");
		var agentCustomerSeq = $("input[name='agentCustomerSeq']");
		
		if(!input_nullCheck(agentCompanySeq, "로펌 및 대리인명"))
		{
			return;
		}
		
		if(!input_nullCheck(agentCustomerSeq, "로펌 및 대리인명"))
		{
			return;
		}
		
		$("form[name='invade_complete_mod_form']").submit();
		
	});
	
	$("#admin_invade_edit").click(function(){
		$("form[name='invade_admin_mod_form']").submit();
	});
	
	//########### 상표 상담일지 등록 폼 유효성 검사 시작 ################
	$("#btn_brand_reg").click(function(){
		var companySeq = $("input[name='companySeq']");
		var customerSeq = $("input[name='customerSeq']");
		
		var consultingDate = $("input[name='consultingDate']");
		
		
		if(!input_nullCheck(companySeq, "회사및 담당자명"))
		{
			return;
		}
		
		if(!input_nullCheck(customerSeq, "회사및 담당자명"))
		{
			return;
		}
		
		
		if(!input_nullCheck(consultingDate, "상담일자"))
		{
			return;
		}
		
				
		$("form[name='brand_reg_form']").submit();
	});
	
	$("#btn_brand_edit").click(function(){
		var companySeq = $("input[name='companySeq']");
		var customerSeq = $("input[name='customerSeq']");
		
		var consultingDate = $("input[name='consultingDate']");
		
		
		if(!input_nullCheck(companySeq, "회사및 담당자명"))
		{
			return;
		}
		
		if(!input_nullCheck(customerSeq, "회사및 담당자명"))
		{
			return;
		}
		
		
		if(!input_nullCheck(consultingDate, "상담일자"))
		{
			return;
		}
		
				
		$("form[name='brand_mod_form']").submit();
	});
	
	
	$("#deleteBrand").click(function(){
		var brandSeq = $("#brandSeq").val();
		var pageNumber = $("#pageNumber").val();
		var deskCode = $("#deskCode").val();
		var fileName = $("#fileName").val();
		var fileSeq = $("#fileSeq").val();
		
		if(confirm("해당글을 정말로 삭제하시겠습니까?")){
			location.href = '/brand/brandDelete.desk?deskCode='+deskCode+'&brandSeq='+brandSeq+'&pageNumber='+pageNumber+'&fileName='+fileName+'&fileSeq='+fileSeq;
		}else{
			return;
		}
	});
	
	$("#brandFileDel").click(function(){
		var brandSeq = $("#brandSeq").val();
		var pageNumber = $("#pageNumber").val();
		var deskCode = $("#deskCode").val();
		var fileName = $("#fileName").val();
		var fileSeq = $("#fileSeq").val();
		//alert(fileSeq);
		if(confirm("해당 파일을 정말로 삭제하시겠습니까?")){
			location.href = '/brand/brandDeleteFile.desk?deskCode='+deskCode+'&brandSeq='+brandSeq+'&pageNumber='+pageNumber+'&fileName='+fileName+'&fileSeq='+fileSeq;
		}else{
			return;
		}
	});
	
	
	//########### 협력채널 구축실적 등록 폼 유효성 검사 시작 ################
	$("#btn_channel_edit").click(function(){
		var channelDate = $("input[name='channelDate']");
		var channelPlace = $("input[name='channelPlace']");
		var channelTitle = $("input[name='channelTitle']");
		var attendCount = $("input[name='attendCount']");
		var discussIssue = $("textarea[name='discussIssue']");
		
		
		if(!input_nullCheck(channelDate, "개최일자"))
		{
			return;
		}
		
		if(!input_nullCheck(channelPlace, "장소"))
		{
			return;
		}
		
		if(!input_nullCheck(channelTitle, "제목"))
		{
			return;
		}
		
		if(attendCount.val())
		{
			if(!check_numeric(attendCount, "참석자"))
			{
				return;
			}
		}
		
		if(!input_nullCheck(discussIssue, "주요 논의사항"))
		{
			return;
		}
		
		
		$("form[name='channel_mod_form']").submit();
	});
	
	$("#channelFileDel").click(function(){
		var channelSeq = $("#channelSeq").val();
		var pageNumber = $("#pageNumber").val();
		var deskCode = $("#deskCode").val();
		var fileName = $("#fileName").val();
		var fileSeq = $("#fileSeq").val();
		//alert(fileSeq);
		if(confirm("해당 파일을 정말로 삭제하시겠습니까?")){
			location.href = '/channel/channelDeleteFile.desk?deskCode='+deskCode+'&channelSeq='+channelSeq+'&pageNumber='+pageNumber+'&fileName='+fileName+'&fileSeq='+fileSeq;
		}else{
			return;
		}
	});
	
	$("#deleteChannel").click(function(){
		var channelSeq = $("#channelSeq").val();
		var pageNumber = $("#pageNumber").val();
		var deskCode = $("#deskCode").val();
		var fileName = $("#fileName").val();
		var fileSeq = $("#fileSeq").val();
		
		if(confirm("해당글을 정말로 삭제하시겠습니까?")){
			location.href = '/channel/channelDelete.desk?deskCode='+deskCode+'&channelSeq='+channelSeq+'&pageNumber='+pageNumber+'&fileName='+fileName+'&fileSeq='+fileSeq;
		}else{
			return;
		}
	});
	
	
	
	$("#searchInvade").click(function(){
		var startDtTemp	= $("#datepicker1").val();
		var startDt 	= startDtTemp.split("-").join("");
		var endDtTemp	= $("#datepicker2").val();
		var endDt		= endDtTemp.split("-").join("");
		if(startDt > endDt){
			alert("시작일자는 종료일자보다 같거나 작아야 합니다.");
			return;
		}else{
			location.href = '/analysis/analysisInvadeList.desk?startDt='+startDtTemp+'&endDt='+endDtTemp;
		}
	});
	
	
	$("#searchConsult").click(function(){
		var startDtTemp	= $("#datepicker1").val();
		var startDt 	= startDtTemp.split("-").join("");
		var endDtTemp	= $("#datepicker2").val();
		var endDt		= endDtTemp.split("-").join("");
		if(startDt > endDt){
			alert("시작일자는 종료일자보다 같거나 작아야 합니다.");
			return;
		}else{
			location.href = '/analysis/analysisConsultList.desk?startDt='+startDtTemp+'&endDt='+endDtTemp;
		}
	});
	
	$("#searchBrand").click(function(){
		var startDtTemp	= $("#datepicker1").val();
		var startDt 	= startDtTemp.split("-").join("");
		var endDtTemp	= $("#datepicker2").val();
		var endDt		= endDtTemp.split("-").join("");
		if(startDt > endDt){
			alert("시작일자는 종료일자보다 같거나 작아야 합니다.");
			return;
		}else{
			location.href = '/analysis/analysisBrandList.desk?startDt='+startDtTemp+'&endDt='+endDtTemp;
		}
	});
	
	
	$("#searchDesign").click(function(){
		var startDtTemp	= $("#datepicker1").val();
		var startDt 	= startDtTemp.split("-").join("");
		var endDtTemp	= $("#datepicker2").val();
		var endDt		= endDtTemp.split("-").join("");
		if(startDt > endDt){
			alert("시작일자는 종료일자보다 같거나 작아야 합니다.");
			return;
		}else{
			location.href = '/analysis/analysisDesignList.desk?startDt='+startDtTemp+'&endDt='+endDtTemp;
		}
	});
	
	$("#brandSearch").click(function(){
		var keyword = $("#brandSearchKeyword").val();
		
		//if(keyword == ''){
		//	alert("검색어를 입력하세요.");
		//	return false;
		//}else{
			$("#brandList").attr('action','/brand/brandList.desk').submit();
		//}
		
	});
	
	$("#brandSearchKeyword").keydown(function(evt){
		var keyword = $("#brandSearchKeyword").val();
		if(evt.keyCode == 13){
			if(keyword == ''){
				alert("검색어를 입력하세요.");
				return false;
			}else{
				
				$("#brandList").attr('action','/brand/brandList.desk').submit();
			}
		}
	});
	
	
	$(".getListByMonthInSeminar").click(function(){
		var month = $(this).text().trim();
		month = month.substr(0,2);
		var where = "seminar";
		//alert(month);
		window.open('/analysis/analysisSeminarListByMonth.desk?month='+month+'&where='+where, '',"width=765,height=650,scrollbars=yes,left=300,top=150");
	});
	
	$(".getListByMonthInChannel").click(function(){
		var month = $(this).text().trim();
		month = month.substr(0,2);
		var where = "channel";
		//alert(month);
		window.open('/analysis/analysisChannelListByMonth.desk?month='+month+'&where='+where, '',"width=765,height=650,scrollbars=yes,left=300,top=150");
	});
	
	$(".getListByMonthInPromote").click(function(){
		var month = $(this).text().trim();
		month = month.substr(0,2);
		var where = "promote";
		//alert(month);
		window.open('/analysis/analysisPromoteListByMonth.desk?month='+month+'&where='+where, '',"width=765,height=650,scrollbars=yes,left=300,top=150");
	});
	
	
	
	/*
	 * 폼유효성 검사 함수 모음
	 *
	 */
	
	// input Null 값 체크.
	function input_nullCheck(obj, alert_string)
	{
		if(!obj.val())
		{
			if(alert_string != null)
			{
				alert(alert_string + " 을(를) 입력하세요");
				obj.focus();
				return false;
			}
						
		}
		
		return true;
	}

	// 숫자체크 정규표현식 설정 함수.	
	function check_numeric(obj, alert_string)
	{
		str = obj.val();
		var reg1 = /^[0-9]+$/;
		//var reg2 = /[0-9]/g;
		
		if(!(reg1.test(str)))
		{
			alert(alert_string + " 는(은)  숫자만 입력가능합니다");
			obj.val("");
			obj.focus();
			return false;
		}
		return true;
	}
});